package com.wenjunwu.blog.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wenjunwu.blog.dao.BlogCommentDao;
import com.wenjunwu.blog.entity.BlogComment;
import com.wenjunwu.blog.service.BlogCommentService;

@Service
public class BlogCommentServiceImpl implements BlogCommentService {

	@Autowired
	private BlogCommentDao blogCommentDao;

	@Override
	public int save(BlogComment blogComment) {
		blogComment.setCreateTime(new Date());
		return blogCommentDao.insert(blogComment);
	}

	@Override
	public List<BlogComment> find(Map<String, Object> params) {
		return blogCommentDao.selectByParams(params);
	}

	@Override
	public PageInfo<BlogComment> findCommentPage(Map<String, Object> params) {
		int pageNum = Integer.valueOf(params.get("pageNum").toString());
		int pageSize = Integer.valueOf(params.get("pageSize").toString());
		params.remove("pageNum");
		params.remove("pageSize");
		PageInfo<BlogComment>pageInfo = PageHelper.startPage(pageNum, pageSize).doSelectPageInfo(() -> blogCommentDao.selectByParams(params));
		return pageInfo;
	}

	@Override
	public int deleteComment(Long id) {
		return blogCommentDao.deleteByPrimaryKey(id);
	}

}
